package com.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.model.ReponseDto;
import com.model.SysMenu;
import com.service.IMenuService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping(value = "/menu")
@Api(tags = "菜单管理", value = "菜单管理相关api")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @RequestMapping(value = "/list")
    @ApiOperation(value = "菜单列表")
    @ApiImplicitParams({})
    public ReponseDto<List<SysMenu>> list(Model model, HttpServletRequest request) {
        return menuService.list(null);
    }

    @RequestMapping(value = "/add")
    @ApiOperation(value = "添加菜单")
    @ApiImplicitParams({})
    public ReponseDto<String> add(Model model, HttpServletRequest request, @RequestBody SysMenu sysMenu,
            @RequestHeader String userId, @RequestHeader String username) {
        return menuService.add(sysMenu, userId, username);
    }

    @RequestMapping(value = "/update")
    @ApiOperation(value = "编辑菜单")
    @ApiImplicitParams({})
    public ReponseDto<String> update(Model model, HttpServletRequest request, @RequestBody SysMenu sysMenu,
            @RequestHeader String userId, @RequestHeader String username) {
        return menuService.update(sysMenu, userId, username);
    }

    @RequestMapping(value = "/delete")
    @ApiOperation(value = "删除菜单")
    @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "id", required = true   ) })
    public ReponseDto<String> delete(Model model, HttpServletRequest request, Long id, @RequestHeader String userId,
            @RequestHeader String username) {
        return menuService.delete(id, userId, username);
    }
}
